using System;
using System.Windows;
using WPFPractice.Utils;
using WPFPractice.ViewModels;
using WPFTemplateLib.WpfHelpers;

namespace WPFPractice.Windows
{
	/// <summary>
	/// WinZoomInOut.xaml 的交互逻辑
	/// </summary>
	public partial class WinZoomInOut : Window
	{
		public WinZoomInOut()
		{
			InitializeComponent();
			DataContext = new WinZoomInOutViewModel();
		}

		public void Test()
		{
			scroll.LineDown();
		}
	}
}

namespace WPFPractice.ViewModels
{
	public class WinZoomInOutViewModel : MyViewModelBase
	{
		#region 成员、构造

		private const double DefaultZoom = 3;

		#endregion

		#region 绑定

		/// <summary>
		/// 缩放比例
		/// </summary>
		public double Zoom { get; set; } = DefaultZoom;

		/// <summary>
		/// 缩放百分比
		/// </summary>
		public double ZoomPercentage { get; set; } = 0.1;

		/// <summary>
		/// 最小缩放比率
		/// </summary>
		public double MinZoom { get; set; } = 0.1;

		/// <summary>
		/// 最大缩放比率
		/// </summary>
		public double MaxZoom { get; set; } = 5;

		/// <summary>
		/// 内容原始宽度
		/// </summary>
		public double ContentOriginWidth { get; set; } = 400;

		/// <summary>
		/// 内容原始高度
		/// </summary>
		public double ContentOriginHeight { get; set; } = 300;

		#endregion

		#region 命令

		#region [命令] 改变缩放
		private RelayCommand<bool?> _ChangeZoomCmd;
		public RelayCommand<bool?> ChangeZoomCmd => _ChangeZoomCmd ??= new RelayCommand<bool?>(ExecuteChangeZoomCmd);
		private void ExecuteChangeZoomCmd(bool? para)
		{
			if(para == null)
			{
				Zoom = DefaultZoom;
			}
			else
			{
				bool isZoomIn = (bool)para;
				if(isZoomIn)
				{
					if(Zoom + ZoomPercentage <= MaxZoom)
					{
						Zoom += ZoomPercentage;
					}
					else
					{
						ToastToScreenWarning($"已限制最大缩放比为 {MaxZoom}");
					}
				}
				else
				{
					if(Zoom - ZoomPercentage >= MinZoom)
					{
						Zoom -= ZoomPercentage;
					}
					else
					{
						ToastToScreenWarning($"已限制最小缩放比为 {MinZoom}");
					}
				}
			}
		}
		#endregion

		#endregion

		#region 方法

		protected override void InitDataAfterConstruction()
		{
			Console.WriteLine("演示 界面缩放");
		}

		#endregion
	}
}
